Generating the Contour Line Plot and the Mask¶

In this notebook, we will generate the contour line plot and the mask for example that we have been using in the previous notebooks. We want to know if it is hard to generate both the contour line plot and the mask.

Define Data¶

In [ ]:
import numpy as np

Al = np.array([0.0, 0.0, 0.0, 0.0, 1.0 / 3, 1.0 / 3, 1.0 / 3, 2.0 / 3, 2.0 / 3, 1.0])
Cu = np.array([0.0, 1.0 / 3, 2.0 / 3, 1.0, 0.0, 1.0 / 3, 2.0 / 3, 0.0, 1.0 / 3, 0.0])
Y = 1 - Al - Cu
# synthetic data for mixing enthalpy
# See https://pycalphad.org/docs/latest/examples/TernaryExamples.html
enthalpy = (Al - 0.01) * Cu * (Al - 0.52) * (Cu - 0.48) * (Y - 1) ** 2
coordinates = np.array([Al, Y, Cu])

Generate the Contour Line Plot¶

In [ ]:
import plotly.graph_objects as go
from plotly.figure_factory._ternary_contour import create_ternary_contour

contour_line_fig = create_ternary_contour(
    coordinates,
    enthalpy,
    pole_labels=["Al", "Y", "Cu"],
    interp_mode="cartesian",
    coloring="lines",
    linecolor="black",
    width=700,
    height=700,
)

contour_line_fig.update_ternaries(
    dict(
        aaxis_showgrid=False,
        baxis_showgrid=False,
        caxis_showgrid=False,
        bgcolor="rgba(0,0,0,0)",
    )
)

contour_line_fig.update_layout(paper_bgcolor="rgba(0,0,0,0)")

contour_line_fig.add_trace(
    go.Scatterternary(
        a=[1, 0, 0, 1],
        b=[0, 1, 0, 0],
        c=[0, 0, 1, 0],
        mode="lines",
        line=dict(color="black", width=14),
        fill="toself",
        fillcolor="rgba(0,0,0,0)",
        name="border",
    )
)
contour_line_fig.show()

Generate the Mask¶

In [ ]:
mask_fig = create_ternary_contour(
    coordinates,
    enthalpy,
    pole_labels=["", "", ""],
    interp_mode="cartesian",
    width=700,
    height=700,
)

mask_fig.update_traces(dict(line=dict(color="rgba(0,0,0,0)", width=0)))

axis_dict = dict(
    showgrid=False,
    ticks="",
    tickmode="array",
    tickvals=[],
    linewidth=0,
    color="rgba(0,0,0,0)",
)

layout_dict = dict(
    ternary=dict(
        aaxis=axis_dict,
        baxis=axis_dict,
        caxis=axis_dict,
        bgcolor="rgba(0,0,0,0)",
    ),
    paper_bgcolor="rgba(0,0,0,0)",
)

mask_fig.update_layout(layout_dict)
mask_fig.show()

Conclusion¶

It is not hard to generate both the contour line plot and the mask from the same data. This notebook is a good example of how to do it and can be used as a reference for future notebooks. However, the mask and the contour line plot are not tested for the same dimensions. Ideally the mask should fit the contour line plot pixel by pixel. How to do this is left as an exercise for another notebook.